package io.jpress.module.product.directive;

import com.jfinal.aop.Inject;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;
import io.jboot.web.directive.annotation.JFinalDirective;
import io.jboot.web.directive.base.JbootDirectiveBase;
import io.jpress.commons.bean.RenderList;
import io.jpress.module.product.model.ProductImage;
import io.jpress.module.product.service.ProductImageService;

import java.util.List;


@JFinalDirective("productImages")
public class ProductImagesDirective extends JbootDirectiveBase {

    @Inject
    private ProductImageService imageService;

    @Override
    public void onRender(Env env, Scope scope, Writer writer) {
        Long productId = getParaToLong(0,scope);
        List<ProductImage> articleImages = imageService.findListByProductId(productId);
        scope.setLocal("articleImages",new RenderList<>(articleImages));
        renderBody(env,scope,writer);
    }

    @Override
    public boolean hasEnd() {
        return true;
    }
}
